home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / qbnws302.zip / LINEDIT.ZIP / LINEEDIT.BAS < prev    next >
BASIC Source File  |  1992-03-22  |  18KB  |  417 lines

  1. DEFINT A-Z
  2. '+==================================================================+
  3. '|                           LINEEDIT.BAS                           |
  4. '|                                                                  |
  5. '|  A line edit routine developed by Larry Stone and the SWOCC      |
  6. '|  students of Larry Stone, CS133B, Fall Term '91, SWOCC.          |
  7. '|                                                                  |
  8. '|  Purpose:  Line editor that can edit a string in a virtual       |
  9. '|            window, VwindowSize%, bigger than the allowable       |
  10. '|            display length, DisplayLen%                           |
  11. '|                                                                  |
  12. '|  Modules:  LINEEDIT                                              |
  13. '|            KEYBOARD                                              |
  14. '|                                                                  |
  15. '|  Call:     LineEdit Row%, Col%, CurPos%, A$, VwindowSize%, _     |
  16. '|                     DisplayLen%, CuroffSet%, Kee%, Separaters$,_ |
  17. '|                     Terminators()                                |
  18. '+------------------------------------------------------------------+
  19. '
  20. '+==================================================================+
  21. '|                           DECLARATIONS                           |
  22. '+------------------------------------------------------------------+
  23. '
  24. DECLARE FUNCTION InsertState% ()
  25. DECLARE FUNCTION KeyPressed% ()
  26. DECLARE FUNCTION Lower% (Value%)
  27. DECLARE SUB RingSound ()
  28. DECLARE FUNCTION Upper% (Value%)
  29.  
  30. CONST False = 0, True = NOT False
  31.  
  32. '+==================================================================+
  33. '|                            SUBPROGRAMS                           |
  34. '+------------------------------------------------------------------+
  35.  
  36. '+======================================================================+
  37. '|                           LIneEdit Subprogram                        |
  38. '|                                                                      |
  39. '|  Developed by: Larry Stone & his students during Fall & Winter term, |
  40. '|                1991-1992, Southwestern Oregon Community College.     |
  41. '|                                                                      |
  42. '|  Purpose:  Line editor that can scroll/edit a virtual window longer  |
  43. '|            than the displayable line.                                |
  44. '|                                                                      |
  45. '|  Input:  Row%            The Row to display the edit string.         |
  46. '|          Col%            The starting column for the edit string.    |
  47. '|          VwindowSize%    The length of optional virtual window.      |
  48. '|                          If VwindowSize is less than DisplayLen then |
  49. '|                          it is automatically sized to DisplayLen.    |
  50. '|          DisplayLen%     The length allowed for string display.      |
  51. '|          Separaters$     String defining word separaters.            |
  52. '|          AutoTerminate%  Boolean statement - If true, terminates     |
  53. '|                          LineEdit when CurPos is at end of field.    |
  54. '|          Terminators%()  Integer Array defining exit key strokes.    |
  55. '|                          Zeroeth element defines last terminator     |
  56. '|                          used.  MUST BE DIMMED IN CALLING PROGRAM!   |
  57. '|                                                                      |
  58. '|          EditMask$       Optional string of symbols that serve to    |
  59. '|                          mask the corresponding character in the     |
  60. '|                          the edit string (A$).                       |
  61. '|                                                                      |
  62. '|              # chr(35)   digits 0-9 and any uppercase character      |
  63. '|              A chr(65)   uppercase only (converts to upper case)     |
  64. '|              9 chr(57)   digits 0-9 only                             |
  65. '|              ? chr(63)   anything at all                             |
  66. '|              8 chr(56)   digits 0-9, uppercase, "/", or space        |
  67. '|              * chr(42)   any alpha, dash, apostraphe or space        |
  68. '|              a chr(97)   lower case alpha only                       |
  69. '|                                                                      |
  70. '|  Input/Output:                                                       |
  71. '|          A$              The string to edit - the edited string.     |
  72. '|          CurPos%         Cursor location within the displayed string |
  73. '|                          (use value as input to re-edit string).     |
  74. '|          CurOffset%      Adjustment factor for left-most character   |
  75. '|                          of the displayed string (use value as input |
  76. '|                          to re-edit string).                         |
  77. '|                                                                      |
  78. '|  Output: Kee%            The exit key user hit to exit this routine. |
  79. '|                                                                      |
  80. '|  Note:   Extended keys, ie., up/down arrow, are returned as negative |
  81. '|          numbers.                                                    |
  82. '|                                                                      |
  83. '|  Edit Functions:                                                     |
  84. '|          Backspace       Deletes character to left of cursor         |
  85. '|          Delete          Deletes character under cursor              |
  86. '|          Ctrl + Home     Deletes from cursor to beginning of line    |
  87. '|          Ctrl + End      Deletes from cursor to end of line          |
  88. '|          Ctrl + Right    Move to word on right (skips separaters)    |
  89. '|          Ctrl + Left     Move to word on left (skips separaters)     |
  90. '|          Home            Move to beginning of string                 |
  91. '|          End             Move to space after last char of string     |
  92. '|          Right           Move cursor one character to right          |
  93. '|          Left            Move cursor one character to left           |
  94. '|                                                                      |
  95. '+----------------------------------------------------------------------+
  96. '
  97. SUB LineEdit (Row%, Col%, CurPos%, A$, VwindowSize%, DisplayLen%, CurOffset%, Kee%, Separaters$, Terminators(), EditMask$, AutoTerminate%)
  98.  
  99.     IF VwindowSize% < DisplayLen% THEN VwindowSize% = DisplayLen%
  100.     IF CurPos = False THEN CurPos = 1       'Set cursor position
  101.     Escan = 7                               'Set End Scan Line
  102.    
  103.     '---- Insert is either On or Off
  104.     InsIsOn% = InsertState%
  105.     
  106.     GOSUB DisplayLine                       'Display the string to edit
  107.     COLOR 14, False                         'Force color change with edits
  108.  
  109.     IF LEN(EditMask$) THEN                  'If we have an edit mask...
  110.         IF LEN(EditMask$) < VwindowSize% THEN  'and it a wee short...
  111.             '---- Pad the edit mask with "?" (anything) symbols
  112.             EditMask$ = EditMask$ + STRING$(VwindowSize% - LEN(EditMask$), 63)
  113.         END IF
  114.     END IF
  115.     
  116.     DO
  117.         DO
  118.             LastIns = InsIsOn               'Save the state of the Ins key
  119.             Kee% = KeyPressed%              'Get a key from keyboard buffer
  120.  
  121.             '---- If Insert is changed then toggle the state of InsIsOn
  122.             IF Kee = -82 THEN Kee = False: InsIsOn = InsIsOn XOR True
  123.             IF LastIns <> InsIsOn THEN GOSUB SetLocation
  124.  
  125.             '---- Loop to the last terminator used.  Is it our keystroke?
  126.             FOR N = 1 TO Terminators(False)
  127.                 IF Terminators(N) = Kee% THEN Terminated = True
  128.             NEXT
  129.         LOOP UNTIL Kee%
  130.         IF Terminated THEN EXIT DO
  131.  
  132.         StrPos = CurPos + CurOffset           'Pointer into the string
  133.         CharOK = True                         'Initialize this to true
  134.         IF LEN(EditMask$) THEN
  135.             '---- If Kee isn't an extended keystroke, backspace or enter...
  136.             IF NOT (Kee% < False OR Kee = 8 OR